package com.webapp.beans;

import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Service;

import com.webapp.interfaces.LoginData;

@Service
public class UserData implements LoginData {

	
	public String getLogin() {
		User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		String login = user.getUsername();
		return login;
	}
	
	
	public String getPassword() {
		User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		String password = user.getPassword();
		return password;
	}

	
	public List<GrantedAuthority> getRole() {
		User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		List<GrantedAuthority> autorities = (List<GrantedAuthority>) user.getAuthorities();
		return autorities;
	}
	
}
